package com.atguigu.async;

import com.atguigu.exception.SleepUtils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer;
import java.util.function.Function;

public class FutureDemo3 {
    public static void main(String[] args) throws Exception{
        runAsync1();
        runAsync2();
        System.out.println("main");
        SleepUtils.sleep(3);
    }

    public static void runAsync1(){
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"你好runAsync1");
            }
        }).whenComplete(new BiConsumer<Void, Throwable>() {
            @Override
            public void accept(Void acceptVoid, Throwable throwable) {
                System.out.println(Thread.currentThread().getName()+"1异步执行后接收的值"+acceptVoid);
            }
        });
    }
    public static void runAsync2(){
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"你好runAsync2");
            }
        }).whenCompleteAsync(new BiConsumer<Void, Throwable>() {
            @Override
            public void accept(Void acceptVoid, Throwable throwable) {
                System.out.println(Thread.currentThread().getName()+"2异步执行后接收的值"+acceptVoid);
            }
        });
    }
}
